
$(function(){
	$('.sycn-chosen').each(function(i,e){
		var _this=$(e);
		var url=_this.attr('data-url');
		var width=_this.attr('width');
		var selectId=_this.attr('selectId');
		 $.ajax({  
		        type: "post",  
		        url: url,  
		        async: false,
		        contentType: "application/json; charset=utf-8",  
		        dataType: "json",  
		        success: function(data) {  
		           $(data).each(function(j,ele){
		        	   if(selectId!=null&&selectId==ele.value){
		        		   $('<option value="'+ele.value+'" selected="selected" >'+ele.text+'</option>').appendTo(_this);
		        	   }else{
		        		   $('<option value="'+ele.value+'">'+ele.text+'</option>').appendTo(_this);
		        	   }
		        	  
		           });
		        },
		        complete:function(){
		        	$(_this).chosen({allow_single_deselect:true});
		        	if(width==null){
		        		width=200;
		        	}
		        	_this.next().css({'width': width});
		        }
		    });  
	});

});
(function($){
	$.fn.serializeJson=function(){
		var serializeObj={};
		var array=this.serializeArray();
		var str=this.serialize();
		$(array).each(function(){
			if(serializeObj[this.name]){
				if($.isArray(serializeObj[this.name])){
					serializeObj[this.name].push(this.value);
				}else{
					serializeObj[this.name]=[serializeObj[this.name],this.value];
				}
			}else{
				serializeObj[this.name]=this.value;	
			}
		});
		return serializeObj;
	};
})(jQuery);